package component;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * Description: 数据格式转换工具类
 */
public class Data {

    public static String readBody(HttpServletRequest req) {
        int contentLength = req.getContentLength();
        byte[] buffer = new byte[contentLength];
        try {
            InputStream inputStream = req.getInputStream();
            inputStream.read(buffer);
            return new String(buffer, "utf8");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
